﻿using System.Text;
using Ctef.Web.Models;
using Ctef.Web.Resources.Involve;

namespace Ctef.Web.Extensions
{
    public static class VolunteerInfoExtensions
    {
        public static bool IsValid(this VolunteerInfoViewModel model)
        {
            return !(model == null || model.Name.IsNullOrWhiteSpace() ||
                model.Email.IsNullOrWhiteSpace() || model.Phone.IsNullOrWhiteSpace() ||
                model.Occupation.IsNullOrWhiteSpace());
        }

        public static string ComposeEmailSubject(this VolunteerInfoViewModel model)
        {
            if (model == null || model.Name.IsNullOrWhiteSpace())
            {
                return null;
            }

            return "[CTEF volunteer] new signup from " + model.Name.Trim();
        }

        public static string ComposeEmailBody(this VolunteerInfoViewModel model)
        {
            if (model == null)
            {
                return null;
            }

            var buffer = new StringBuilder();
            buffer.Append("Name: "); buffer.AppendLine(model.Name.TrimOrEmpty());
            buffer.Append("Email: "); buffer.AppendLine(model.Email.TrimOrEmpty());
            buffer.Append("Phone: "); buffer.AppendLine(model.Phone.TrimOrEmpty());

            // TODO: use grouped checkbox helper to simplify both rendering and processing logic
            buffer.AppendLine("Interested in projects:");
            if (model.Schools)
            {
                buffer.AppendLine(Strings.Volunteer_Answer_Projects_School);
            }

            if (model.Website)
            {
                buffer.AppendLine(Strings.Volunteer_Answer_Projects_Web);
            }

            if (model.PublicRelations)
            {
                buffer.AppendLine(Strings.Volunteer_Answer_Projects_PR);
            }

            if (model.Events)
            {
                buffer.AppendLine(Strings.Volunteer_Answer_Projects_Events);
            }

            buffer.AppendLine();
            var locKey = "Volunteer_Answer_Time_" + model.Time;
            buffer.AppendFormat("Time commitment: {0}", Strings.ResourceManager.GetString(locKey));
            buffer.AppendLine();

            buffer.Append("Occupation: "); buffer.AppendLine(model.Occupation.TrimOrEmpty());
            buffer.Append("Other information: "); buffer.AppendLine(model.AdditionalInfo.TrimOrEmpty());
            return buffer.ToString();
        }
    }
}